home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of Down Under Games
/
The Best of Down Under Games.iso
/
3dfx Screen Savers
/
Impact
/
IMPSRC.ZIP
/
THINGS.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-22
|
51KB
|
1,762 lines
#include "winstuff.h"
#include "things.h"
#include <stdio.h>
#include "dmouse.h"
#include "myjoy.h"
#include "math.h"
#include "trigs.h"
#include "land.h"
//Matrix rotx, roty, rotz, rotc, rote, roto, tranm;
float Camx,Camy,Camz,Camzoomx,Camzoomy;
int TryCount,OldTryCount,AttCount,AttOld,frameCount;
char MyS[256];
float wWidth, wHeight,worker,wHWidth,wHHeight,GDx,GDy;
float gfov;
float aspect;
int joynum=0;
int dist = 8*1024;
double Nextshot = 0;
entity_t *Self, *Other,*Head,*Tail;
void entity_t::LoadLWO(char *mlwo){
//Print(mlwo);
FILE *lwo;
short nada,leng,num,corn;
int tmp,tmp2,tmp3;
//int tmp
float pnt;
long posi,size;
char String[1024];
unsigned char J[3]={0,0,0};
size = filesize(mlwo);
lwo = fopen(mlwo, "rb");
if(!lwo) {
sprintf(MyS,"..\\system\\%s",mlwo);
size = filesize(MyS);
lwo = fopen(MyS, "rb");
if(!lwo)
return;
}
lwon = new char[strlen(mlwo)+1];
entity_t *Find = Head;
//Print("Finding");
while(Find){
//Print(Find->lwon);
//Print(mlwo);
if(Find->lwon && !strcmpi(Find->lwon,mlwo)){
break;
}
Find=Find->next;
if(Tail == Head)
Find = 0;
}
//Print("Found done");
if(Find){
//Print("found");
strcpy(lwon,mlwo);
NumVerts = Find->NumVerts;
/*Verts = Find->Verts;
NumTris = Find->NumTris;
Tris = Find->Tris;
NumSurfs = Find->NumSurfs;
Surfs = Find->Surfs;*/
Verts = new GrVertex[NumVerts];
if(!Verts) Print("NoVerts!");
lit = new light_t[NumVerts];
if(!lit) Print("NoLit!");
memcpy(Verts,Find->Verts,sizeof(GrVertex)*NumVerts);
NumTris = Find->NumTris;
Tris = new faces_t[NumTris];
if(!Tris) Print("NoTris!");
memcpy(Tris,Find->Tris,sizeof(faces_t)*NumTris);
for(tmp = 0;tmp<NumTris;tmp++){
//Tris[tmp].NumSides = Find->Tris[tmp].NumSides;
Tris[tmp].ndx = new int[Tris[tmp].NumSides];
if(!Tris[tmp].ndx) Print("No index!");
memcpy(Tris[tmp].ndx,Find->Tris[tmp].ndx,sizeof(int)*Tris[tmp].NumSides);
}
NumSurfs = Find->NumSurfs;
//sprintf(MyS,"%i",NumSurfs);
//Print(MyS);
Surfs = new SURFS[NumSurfs];
if(!Surfs) Print("NoSurfs!");
memcpy(Surfs,Find->Surfs,sizeof(SURFS)*NumSurfs);
for(tmp = 0;tmp<NumSurfs;tmp++){
tmp2=strlen(Find->Surfs[tmp].Name)+1;
Surfs[tmp].Name = new char[tmp2];
memcpy(Surfs[tmp].Name,Find->Surfs[tmp].Name,tmp2);
}
fclose(lwo);
return;
}
//Print("No Match");
strcpy(lwon,mlwo);
fread(&String, sizeof(char),6,lwo);//Get the "form\0\0"
if (strcmpi(String,"FORM")!=0) return;
fread(&nada,sizeof(short),1,lwo);
fread(&String,sizeof(char),4,lwo);
if (strcmpi(String,"LWOB")!=0) return;
//sprintf(MyS,"%i",tmp);
//Print(MyS);
posi = 0;
leng = 0;
while(posi + leng + 1 < size){
posi = ftell(lwo);
fread(&String,sizeof(char),6,lwo);
//Print(String);
fread(&leng,sizeof(short),1,lwo);
leng = BigShort(leng);
if(!strcmpi(String,"pnts")){
//Print(String);
//sprintf(MyS,"%i",leng);
//Print(MyS);
NumVerts = leng/12;
//sprintf(MyS,"%i",NumVerts);
//Print(MyS);
Verts = new GrVertex[NumVerts];
lit = new light_t[NumVerts];
MatMakeYRot(roty, MaxAng/2);
for(tmp = 0;tmp<NumVerts;tmp++){
fread(&pnt,sizeof(float),1,lwo);
Verts[tmp].x = BigFloat(pnt);//*8;
fread(&pnt,sizeof(float),1,lwo);
Verts[tmp].y = BigFloat(pnt);//*8;
fread(&pnt,sizeof(float),1,lwo);
Verts[tmp].z = BigFloat(pnt);//*8;
//sprintf(MyS,"%f %f %f",Verts[tmp].x,Verts[tmp].y,Verts[tmp].z);
//Print(MyS);
//tmp2 = (Verts[tmp].y+16)*8;
//if (tmp2 > 255) tmp2 = 255;
//if (tmp2 <0) tmp2 = 0;
Verts[tmp].r = 0;
Verts[tmp].g = 128;
Verts[tmp].b = 128;
Verts[tmp].a = 255;
PointMatMult(&Verts[tmp],&Verts[tmp],roty);
}
}
else if(!strcmpi(String,"Pols")){
//Print(String);
//Damned thing won't tell me how many faces there are. I have to count first.
posi = ftell(lwo);
tmp = 0;
while (posi+leng > ftell(lwo)){
tmp++;
fread(&num,sizeof(short),1,lwo);
num=BigShort(num)*2;
fseek(lwo,num,SEEK_CUR);
fread(&num,sizeof(short),1,lwo);
num = BigShort(num);
if(num < 0)
fread(&num,sizeof(short),1,lwo);
}
Tris = new faces_t[tmp];
NumTris = tmp;
fseek(lwo,posi,SEEK_SET);
//sprintf(MyS," Num Faces: %i",tmp);
//Print(MyS);
for (tmp2 = 0;tmp2<tmp;tmp2++){
fread(&num,sizeof(short),1,lwo);
num = BigShort(num);
Tris[tmp2].NumSides=num;
Tris[tmp2].ndx = new int[num];
//sprintf(MyS,"Sides: %i",num);
for(tmp3 =0;tmp3<num;tmp3++){
fread(&corn,sizeof(short),1,lwo);
Tris[tmp2].ndx[tmp3] = BigShort(corn);
Tris[tmp2].surfclr = 0;
//sprintf(MyS,"%s %i",MyS,Tris[tmp2].ndx[tmp3]);
}
fread(&corn,sizeof(short),1,lwo);
corn = BigShort(corn);
Tris[tmp2].Surf = corn;
if(Tris[tmp2].Surf<0)
Tris[tmp2].Surf=-Tris[tmp2].Surf;
Tris[tmp2].Surf--;
//sprintf(MyS,"%s Surf:%i",MyS,corn);
//Print(MyS);
if(corn < 0)
fread(&corn,sizeof(short),1,lwo);
}
}
else if(!strcmpi(String,"Srfs")){
//Print(String);
//sprintf(MyS,"%i",leng);
posi = ftell(lwo);
//Print(MyS);
tmp = 0;
while (posi+leng > ftell(lwo)){
fread(&J,sizeof(char),2,lwo);
if(J[0]==0 || J[1]==0) tmp++;
}
Surfs=new SURFS[tmp];
NumSurfs=tmp;
fseek(lwo,posi,SEEK_SET);
tmp=0;
String[0] = 0;
while (posi+leng > ftell(lwo)){
fread(&J,sizeof(char),2,lwo);
strcat(String,J);
if(J[0]==0 || J[1]==0) {
tmp2 = strlen(String)+1;
Surfs[tmp].Name = new char[tmp2];
strcpy(Surfs[tmp].Name,String);
//Print(String);
String[0]=0;
tmp++;
}
}
}
else if(!strcmpi(String,"Surf")){
//Print(String);
//sprintf(MyS,"%i",leng);
//Print(MyS);
posi = ftell(lwo);
tmp = 0;
tmp=0;
String[0] = 0;
while (1){
fread(&J,sizeof(char),2,lwo);
strcat(String,J);
if(J[0]==0 || J[1]==0)
break;
}
for(tmp = 0;tmp<NumSurfs;tmp++){
if (!strcmpi(String,Surfs[tmp].Name))
break;
}
if (tmp < NumSurfs){
short leng2;
while (posi+leng > ftell(lwo)){
fread(&String,sizeof(char),4,lwo);
String[4]=0;
fread(&leng2,sizeof(short),1,lwo);
leng2 = BigShort(leng2);
if(!strcmpi(String,"Colr")){
fread(J,sizeof(char),1,lwo);
Surfs[tmp].r = J[0];
//sprintf(MyS,"%i",J[0]);
fread(J,sizeof(char),1,lwo);
Surfs[tmp].g= J[0];
//sprintf(MyS,"%s %i",MyS,J[0]);
fread(J,sizeof(char),1,lwo);
Surfs[tmp].b= J[0];
//sprintf(MyS,"%s %i",MyS,J[0]);
fread(J,sizeof(char),1,lwo);
Surfs[tmp].a= J[0];
//sprintf(MyS,"%s %i",MyS,J[0]);
//Print(MyS);
if(Surfs[tmp].a ==0)
Surfs[tmp].a = 255;
//sprintf(MyS,"col: %i %i %i %i",Surfs[tmp].r,Surfs[tmp].g,Surfs[tmp].b,Surfs[tmp].a);
//Print(MyS);
}
else if(!strcmpi(String,"Flag")){
fread(&nada,sizeof(short),1,lwo);
Surfs[tmp].Flags = BigShort(nada);
}
else if(!strcmpi(String,"Lumi")){
fread(&nada,sizeof(short),1,lwo);
Surfs[tmp].Lumi = BigShort(nada);
}
else if(!strcmpi(String,"Spec")){
fread(&nada,sizeof(short),1,lwo);
Surfs[tmp].Spec = BigShort(nada);
}
else if(!strcmpi(String,"Diff")){
fread(&nada,sizeof(short),1,lwo);
Surfs[tmp].Diff = BigShort(nada);
}
else if(!strcmpi(String,"Refl")){
fread(&nada,sizeof(short),1,lwo);
Surfs[tmp].Refl = BigShort(nada);
}
else if(!strcmpi(String,"Tran")){
fread(&nada,sizeof(short),1,lwo);
//Print("Has Alpha");
Surfs[tmp].a = Surfs[tmp].Tran = /*128-*/BigShort(nada);
//sprintf(MyS,"%i",Surfs[tmp].a);
//Print(MyS);
}
else if(!strcmpi(String,"Glos")){
fread(&nada,sizeof(short),1,lwo);
Surfs[tmp].Glos = BigShort(nada);
}
else if(!strcmpi(String,"TIMG")){
//Print(String);
String[0] = 0;
while (1){
fread(&J,sizeof(char),2,lwo);
strcat(String,J);
if(J[0]==0 || J[1]==0)
break;
}
//Print(String);
}
else if(!strcmpi(String,"CTEX")){
//Print(String);
String[0] = 0;
while (1){
fread(&J,sizeof(char),2,lwo);
strcat(String,J);
if(J[0]==0 || J[1]==0)
break;
}
//Print(String);
}
else{
//Print(String);
sprintf(MyS,"%i",leng2);
//Print(MyS);
fseek(lwo,leng2,SEEK_CUR);
}
}
}
//fseek(lwo,posi,SEEK_SET);
}
else{
//Print(String);
//sprintf(MyS,"%i",leng);
//Print(MyS);
fseek(lwo,leng,SEEK_CUR);
//fclose(lwo);
//return;
}
}
//LoadBall();
fclose(lwo);
}
void entity_t::render(Matrix rotc){
int tmp2,tmp,i,j,k,l,m,cl,sr;
//if(TryCount>600*frameCount) {return;}
//float yaw2;
if(flag == 1) return;
//GrVertex *
rVerts=new GrVertex[NumVerts];
GrVertex Cen;
MatMakeIdent(rote);
MatMakeYRot(roty, yaw);
MatMakeXRot(rotx, pitch);
MatMakeZRot(rotz, roll);
MatMultMat(roty,rote,rote);
MatMultMat(rotx,rote,rote);
MatMultMat(rotz,rote,rote);
for(tmp = 0;tmp<NumVerts;tmp++){
//rVerts[tmp].a = Verts[tmp].a;
//rVerts[tmp].r = Verts[tmp].r;
//rVerts[tmp].g = Verts[tmp].g;
//rVerts[tmp].b = Verts[tmp].b;
if(light == 0 && nolight == 0){
lit[tmp].r=.6;
lit[tmp].g=.6;
lit[tmp].b=.6;
}
else{
lit[tmp].r=1;
lit[tmp].g=1;
lit[tmp].b=1;
}
rVerts[tmp].x = Verts[tmp].x;
rVerts[tmp].y = Verts[tmp].y;
rVerts[tmp].z = Verts[tmp].z;
PointMatMult(&rVerts[tmp],&rVerts[tmp],rote);
rVerts[tmp].x += x;
rVerts[tmp].y += y;
rVerts[tmp].z += z;
}
if(light == 0 && nolight == 0){ //don't light up other lights.
Other = Head;
while(Other){
if(Other != Self && Other->light && Other->locid>-1 && Other->locid<GridNum2 && land[Other->locid].rendered)
castlight(Other);
Other = Other->next;
}
}
for(tmp = 0;tmp<NumVerts;tmp++){
rVerts[tmp].x -= Camx;
rVerts[tmp].y -= Camy;
rVerts[tmp].z -= Camz;
PointMatMult(&rVerts[tmp],&rVerts[tmp],rotc);
rVerts[tmp].ooz =
rVerts[tmp].oow = 1/rVerts[tmp].z;
rVerts[tmp].x = Camzoomx*rVerts[tmp].x*rVerts[tmp].ooz+wHWidth+vertex_snapper;
rVerts[tmp].y = Camzoomy*rVerts[tmp].y*rVerts[tmp].ooz+wHHeight+vertex_snapper;
rVerts[tmp].x -=vertex_snapper;
rVerts[tmp].y -=vertex_snapper;
}
for (tmp2=0;tmp2<NumTris;tmp2++){
//Print("Drawing");
i = Tris[tmp2].ndx[0];
if (rVerts[i].z<1) continue;
sr = Tris[tmp2].Surf;
cl = Tris[tmp2].surfclr;
if(cl == 0){
rVerts[i].r = Surfs[sr].r*lit[i].r;
rVerts[i].g = Surfs[sr].g*lit[i].g;
rVerts[i].b = Surfs[sr].b*lit[i].b;
rVerts[i].a = Surfs[sr].a;
if(rVerts[i].r>255) rVerts[i].r = 255;
if(rVerts[i].g>255) rVerts[i].g = 255;
if(rVerts[i].b>255) rVerts[i].b = 255;
}
else{
rVerts[i].r = Verts[i].r*lit[i].r;
rVerts[i].g = Verts[i].g*lit[i].g;
rVerts[i].b = Verts[i].b*lit[i].b;
rVerts[i].a = Verts[i].a;
if(rVerts[i].r>255) rVerts[i].r = 255;
if(rVerts[i].g>255) rVerts[i].g = 255;
if(rVerts[i].b>255) rVerts[i].b = 255;
}
for(l = 1,m=2;m<Tris[tmp2].NumSides;l++,m++){
AttCount++;
j = Tris[tmp2].ndx[l];
k = Tris[tmp2].ndx[m];
if (rVerts[j].z<1 || rVerts[k].z<1) break;
//Print("Passed z test");
if (//Backface removal
((rVerts[j].x - rVerts[i].x)*
(rVerts[k].y - rVerts[i].y)-
(rVerts[j].y - rVerts[i].y)*
(rVerts[k].x - rVerts[i].x))>0)
break;
//Print("Passed backface test");
if(cl == 0){
if(l == 1){
rVerts[j].r = Surfs[sr].r*lit[j].r;
rVerts[j].g = Surfs[sr].g*lit[j].g;
rVerts[j].b = Surfs[sr].b*lit[j].b;
rVerts[j].a = Surfs[sr].a;
if(rVerts[j].r>255) rVerts[j].r = 255;
if(rVerts[j].g>255) rVerts[j].g = 255;
if(rVerts[j].b>255) rVerts[j].b = 255;
}
rVerts[k].r = Surfs[sr].r*lit[k].r;
rVerts[k].g = Surfs[sr].g*lit[k].g;
rVerts[k].b = Surfs[sr].b*lit[k].b;
rVerts[k].a = Surfs[sr].a;
if(rVerts[k].r>255) rVerts[k].r = 255;
if(rVerts[k].g>255) rVerts[k].g = 255;
if(rVerts[k].b>255) rVerts[k].b = 255;
}
else{
if(l == 1){
rVerts[j].r = Verts[j].r*lit[j].r;
rVerts[j].g = Verts[j].g*lit[j].g;
rVerts[j].b = Verts[j].b*lit[j].b;
rVerts[j].a = Verts[j].a;
if(rVerts[j].r>255) rVerts[j].r = 255;
if(rVerts[j].g>255) rVerts[j].g = 255;
if(rVerts[j].b>255) rVerts[j].b = 255;
}
rVerts[k].r = Verts[k].r*lit[k].r;
rVerts[k].g = Verts[k].g*lit[k].g;
rVerts[k].b = Verts[k].b*lit[k].b;
rVerts[k].a = Verts[k].a;
if(rVerts[k].r>255) rVerts[k].r = 255;
if(rVerts[k].g>255) rVerts[k].g = 255;
if(rVerts[k].b>255) rVerts[k].b = 255;
}
/*if(rVerts[i].x>0 && rVerts[i].x<wWidth &&
rVerts[j].x>0 && rVerts[j].x<wWidth &&
rVerts[k].x>0 && rVerts[k].y<wWidth &&
rVerts[i].y>0 && rVerts[i].y<wHeight &&
rVerts[j].y>0 && rVerts[j].y<wHeight &&
rVerts[k].y>0 && rVerts[k].y<wHeight)
grDrawTriangle(&rVerts[i],&rVerts[j],&rVerts[k]);
else*/
if(rVerts[i].x<0 || rVerts[j].x<0 || rVerts[k].x<0 ||
rVerts[i].y<0 || rVerts[j].y<0 || rVerts[k].y<0 ||
rVerts[i].x>wWidth || rVerts[j].x>wWidth || rVerts[k].x>wWidth ||
rVerts[i].y>wHeight || rVerts[j].y>wHeight || rVerts[k].y>wHeight)
guDrawTriangleWithClip(&rVerts[i],&rVerts[j],&rVerts[k]);
else
grDrawTriangle(&rVerts[i],&rVerts[j],&rVerts[k]);
//Print("Drawn");
TryCount++;
//if(TryCount>600*frameCount) {delete rVerts;return;}
}
//MyDrawTriangle(Verts[i],Verts[j],Verts[k]);
}
//for(tmp = 0;tmp<NumVerts;tmp++){
//}
delete rVerts;
}
entity_t::entity_t(){
Owner = 0;
MyShootTime=0;
ox = oy = oz =
dx = dy = dz =
x = y = z =
yaw = pitch = roll =
ax = ay = az =
dyaw = dpitch = droll =
ayaw = apitch = aroll =
flag =
useinput =
zoomx = zoomy = 0;
Verts = 0;
Tris = 0;
Surfs = 0;
NumSurfs = NumTris = NumVerts =
BoxX[0] = BoxX[1] =
BoxY[0] = BoxY[1] =
BoxZ[0] = BoxZ[1] = 0;
prev = next = 0;
thinktime = 0;
nolight = lightr = lightg = lightb = lighta = light = 0;
die = 0;
lwon=0;
}
entity_t::entity_t(char *lwo){
Owner = 0; MyShootTime=0;
ox = oy = oz =
dx = dy = dz =
x = y = z =
yaw = pitch = roll =
ax = ay = az =
dyaw = dpitch = droll =
ayaw = apitch = aroll =
flag =
useinput =
zoomx = zoomy = 0;
Verts = 0;
Tris = 0;
Surfs = 0;
NumSurfs = NumTris = NumVerts =
BoxX[0] = BoxX[1] =
BoxY[0] = BoxY[1] =
BoxZ[0] = BoxZ[1] = 0;
prev = next = 0;
thinktime = 0;
nolight = lightr = lightg = lightb = lighta = light = 0;
lwon=0;
LoadLWO(lwo);
die = 0;
}
entity_t::entity_t(float ix, float iy, float iz){
Owner = 0; MyShootTime=0;
ox = oy = oz =
dx = dy = dz = 0;
x = ix; y = iy; z = iz;
yaw = pitch = roll =
ax = ay = az =
dyaw = dpitch = droll =
ayaw = apitch = aroll =
flag =
useinput =
zoomx = zoomy = 0;
Verts = 0;
Tris = 0;
Surfs = 0;
NumSurfs = NumTris = NumVerts =
BoxX[0] = BoxX[1] =
BoxY[0] = BoxY[1] =
BoxZ[0] = BoxZ[1] = 0;
prev = next = 0;
thinktime = 0;
nolight = lightr = lightg = lightb = lighta = light = 0;
die = 0;
lwon=0;
}
entity_t::entity_t(float ix, float iy, float iz,float idx, float idy, float idz){
MyShootTime=0;
Owner = 0;
ox = oy = oz = 0;
dx = idx;
dy = idy;
dz = idz;
x = ix;
y = iy;
z = iz;
yaw = pitch = roll =
ax = ay = az =
dyaw = dpitch = droll =
ayaw = apitch = aroll =
flag =
useinput =
zoomx = zoomy = 0;
Verts = 0;
Tris = 0;
Surfs = 0;
NumSurfs = NumTris = NumVerts =
BoxX[0] = BoxX[1] =
BoxY[0] = BoxY[1] =
BoxZ[0] = BoxZ[1] = 0;
prev = next = 0;
thinktime = 0;
nolight = lightr = lightg = lightb = lighta = light = 0;
die = 0;
lwon=0;
}
entity_t::entity_t(float ix, float iy, float iz,float idx, float idy, float idz,float iyaw, float ipitch, float iroll){
MyShootTime=0;
Owner = 0;
ox = oy = oz = 0;
dx = idx;
dy = idy;
dz = idz;
x = ix;
y = iy;
z = iz;
yaw = iyaw;
pitch = ipitch;
roll = iroll;
ax = ay = az =
dyaw = dpitch = droll =
ayaw = apitch = aroll =
flag =
useinput =
zoomx = zoomy = 0;
Verts = 0;
Tris = 0;
Surfs = 0;
NumSurfs = NumTris = NumVerts =
BoxX[0] = BoxX[1] =
BoxY[0] = BoxY[1] =
BoxZ[0] = BoxZ[1] = 0;
prev = next = 0;
thinktime = 0;
nolight = lightr = lightg = lightb = lighta = light = 0;
yaw = iyaw;
pitch = ipitch;
roll = iroll;
die = 0;
lwon=0;
}
entity_t::entity_t(char *rlwo,float ix, float iy, float iz){
MyShootTime=0;
Owner = 0;
ox = oy = oz =
dx = dy = dz = 0;
x = ix;
y = iy;
z = iz;
yaw = pitch = roll =
ax = ay = az =
dyaw = dpitch = droll =
ayaw = apitch = aroll =
flag =
useinput =
zoomx = zoomy = 0;
Verts = 0;
Tris = 0;
Surfs = 0;
NumSurfs = NumTris = NumVerts =
BoxX[0] = BoxX[1] =
BoxY[0] = BoxY[1] =
BoxZ[0] = BoxZ[1] = 0;
prev = next = 0;
thinktime = 0;
nolight = lightr = lightg = lightb = lighta = light = 0;
x = ix;
y = iy;
z = iz;
lwon=0;
LoadLWO(rlwo);
die = 0;
}
entity_t::entity_t(char *lwo,float ix, float iy, float iz,float idx, float idy, float idz){
MyShootTime=0;
Owner = 0;
ox = oy = oz = 0;
dx = idx;
dy = idy;
dz = idz;
x = ix;
y = iy;
z = iz;
yaw = pitch = roll =
ax = ay = az =
dyaw = dpitch = droll =
ayaw = apitch = aroll =
flag =
useinput =
zoomx = zoomy = 0;
Verts = 0;
Tris = 0;
Surfs = 0;
NumSurfs = NumTris = NumVerts =
BoxX[0] = BoxX[1] =
BoxY[0] = BoxY[1] =
BoxZ[0] = BoxZ[1] = 0;
prev = next = 0;
thinktime = 0;
nolight = lightr = lightg = lightb = lighta = light = 0;
dx = idx;
dy = idy;
dz = idz;
lwon=0;
LoadLWO(lwo);
die = 0;
}
entity_t::entity_t(char *lwo,float ix, float iy, float iz,float idx, float idy, float idz,float iyaw, float ipitch, float iroll){
MyShootTime=0;
Owner = 0;
ox = oy = oz =
dx = idx;
dy = idy;
dz = idz;
x = ix;
y = iy;
z = iz;
yaw = iyaw;
pitch = ipitch;
roll = iroll;
ax = ay = az = 0;
dyaw = 0; dpitch = 0; droll = 0;
ayaw = apitch = aroll =
flag =
useinput =
zoomx = zoomy = 0;
Verts = 0;
Tris = 0;
Surfs = 0;
NumSurfs = NumTris = NumVerts =
BoxX[0] = BoxX[1] =
BoxY[0] = BoxY[1] =
BoxZ[0] = BoxZ[1] = 0;
prev = next = 0;
thinktime = 0;
nolight = lightr = lightg = lightb = lighta = light = 0;
lwon=0;
LoadLWO(lwo);
die = 0;
}
void entity_t::setsize(float lx, float ly, float lz, float hx, float hy, float hz){
BoxX[0] = lx;
BoxX[1] = hx;
BoxY[0] = ly;
BoxY[1] = hy;
BoxZ[0] = lz;
BoxZ[1] = hz;
rad = ((hx-lx)/2 + (hy-ly)/2 + (hz-lz)/2)/3 + 2;
}
entity_t::~entity_t(){
int tmp,tmp2,tmp3;
if(next && prev){
//Print("Delete, remove");
prev->next = next;
next->prev = prev;
//Print("Delete, removed");
}
else if(prev){
//Print("Delete, truncate");
Tail = prev;
prev->next = 0;
//Print("Delete, truncated");
}
else if(next){
//Print("Delete, shorten");
Head = next;
next->prev = 0;
//Print("Delete, shortened");
}
if(Verts) {delete Verts;delete lit;}
//Print("Killed Verts");
for(tmp = 0;tmp<NumTris;tmp++)
delete Tris[tmp].ndx;
//Print("Killed Polys");
if(Tris) delete Tris;
//Print("Killed Tris");
for(tmp = 0;tmp<NumSurfs;tmp++)
delete Surfs[tmp].Name;
//Print("Killed Surfs");
if(Surfs) delete Surfs;
//Print("Killed Surfs 2");
if(lwon) delete lwon;
//Print("Killed lwo name");
}
void entity_t::fov(){
zoomx = gfov*wHWidth;
zoomy = gfov*wHHeight*aspect;
Camzoomx = zoomx;
Camzoomy = zoomy;
float alpha2 = alpha/2;
alpha2 = alpha2*MaxAng/360;
FoVTri[0].x = 0;
FoVTri[0].y = 0;
FoVTri[0].z = -450;
FoVTri[1].x = -Sin[(int)alpha2]/Cos[(int)alpha2]*dist;
FoVTri[1].y = 0;
FoVTri[1].z = dist;
FoVTri[2].x = -FoVTri[1].x;
FoVTri[2].y = 0;
FoVTri[2].z = dist;
}
int entity_t::collide(entity_t *Other){
if (Other == Owner) return 0;
int totrad = rad;
//if(Other->rad<100)
totrad+=Other->rad;
//else
// totrad+=12;
float rdx,rdy,rdz,a,b;
rdx = abs(Other->x - x);
rdy = abs(Other->y - y);
rdz = abs(Other->z - z);
if (totrad>rdx && totrad>rdy && totrad>rdz){
//sprintf(MyS,"%s %s %f %f %i %i",lwon,Other->lwon,a,b,rad,Other->rad);
//Print(MyS);
//Print("collide!");
return 1;
}
rdx += abs(Other->ox - ox);
rdy += abs(Other->oy - oy);
rdz += abs(Other->oz - oz);
rdx/=2;
rdy/=2;
rdz/=2;
if (totrad>rdx && totrad>rdy && totrad>rdz){
//sprintf(MyS,"%s %s %f %f %i %i",lwon,Other->lwon,a,b,rad,Other->rad);
//Print(MyS);
//Print("collide!");
return 1;
}
return 0;
}
int entity_t::collide(){//for land
int numg = GridNum*GridNum,vrtx,vrtz;
int lx,lz;
int id = 0;
//for (id=0;id<numg;id++){
// if(x > land[id].minx && x < land[id].maxx && z > land[id].minz && z < land[id].maxz){
// locid=id;
// break;
// }
//}
lx = x/gridsep;
lz = z/gridsep;
if(lx<GridNum && lx>-1 && lz<GridNum && lz>-1)
id = (lx)*GridNum+lz;
else id = -1;
locid = id;
if(movetype == move_roll || movetype == 4 || movetype == move_fly){
if(x<0 || x >= LevMax || z<0 || z >= LevMax || id < 0){
if(movetype == 4){
die = 1;
return 0;
}
//sprintf(MyS,"%f %f (%f %f) (%f %f) %i",x,z,redx,redz,ox,oz,LevMax);
//Print(MyS);
x = random(LevMax);
z = random(LevMax);
return 0;
}
//sprintf(MyS,"%i",id);
//Print(MyS);
lx = x - land[locid].minx;
lz = z - land[locid].minz;
vrtx = x/vertsep;
vrtz = z/vertsep;
if( Start[vrtz*(width)+vrtx].y/*land[locid].Start[vrtz*(tdx+1)+vrtx].y*/ +rad*2 < y){
if(movetype!= move_fly)
ay = -80;
}
else{
y = Start[vrtz*(width)+vrtx].y/*land[locid].Start[vrtz*(tdx+1)+vrtx].y*/+rad*2;
droll = 0;
dy = 5;
ay = 0;
}
}
if(movetype == 3){
if(id == -1) {die = 1;return 1;}
lx = x - land[locid].minx;
lz = z - land[locid].minz;
vrtx = x/vertsep;
vrtz = z/vertsep;
if( Start[vrtz*(width)+vrtx].y/*land[locid].Start[vrtz*(tdx+1)+vrtx].y*/+rad*2 > y){
die = 1;
return 1;
}
}
return 0;
}
int entity_t::move(){
float dxr,dyr,dzr,c,s;
if(flag == 5 && Enemy == 0){
entity_t *Find = Head;
float edu = -1;
while(Find){
if(Find==Self || (Find->movetype != move_roll && Find->movetype != move_fly)){
Find = Find->next;
continue;
}
float fdn = -Find->x+x-Find->redx,
fdm =-Find->z+z-Find->redz,
fdp = -Find->y+y-Find->redy,
fdu = sqrt(fdm*fdm+fdn*fdn+fdp*fdp);
if(edu== -1 || edu>fdu){
Enemy = Find;
edu = fdu;
}
Find = Find->next;
}
}
if(flag == 4 || flag == 5){//Autopiolot
float newyaw=0,newpitch=0,tmpyaw=0,tmppitch=0;
//entity_t *Enemy = next;
float dn = -Enemy->x+x-Enemy->redx,dm =-Enemy->z+z-Enemy->redz,dp = -Enemy->y+y-Enemy->redy,du = sqrt(dm*dm+dn*dn+dp*dp);
if (dm)
newyaw = MaxAng*(atan(dn/dm))/M_PIx2;
else{
if(dn > 0)
newyaw = MaxAng/2;
else
newyaw = 0;
}
if(dm>0)
newyaw+=MaxAng/2;
newpitch = 0;
dz = 1;
if(y < 500){
newpitch = -10*Deg;
}
else if(y > 600){
newpitch = 10*Deg;
}
while(newyaw<0)
newyaw+=MaxAng;
//if(newyaw>MaxAng/2)
// newyaw -=MaxAng;
//if(yaw>MaxAng/2)
// yaw -=MaxAng;
tmpyaw = yaw - newyaw;
if(tmpyaw>MaxAng/2)
tmpyaw-=MaxAng;
if(tmpyaw<-MaxAng/2)
tmpyaw+=MaxAng;
if(tmpyaw<-1.5*Deg){
dyaw=1*Deg;
dz = 1;
}
if(tmpyaw>1.5*Deg){
dyaw=-1*Deg;
dz = 1;
}
if(tmpyaw<-5.5*Deg){
dyaw=5*Deg;
dz = .7;
}
if(tmpyaw>+5.5*Deg){
dyaw=-5*Deg;
dz = .7;
}
if(tmpyaw<-15.5*Deg){
dyaw=15*Deg;
dz = .5;
}
if(tmpyaw>15.5*Deg){
dyaw=-15*Deg;
dz = .5;
}
if(tmpyaw>-Deg && tmpyaw<Deg){
dyaw =0;
yaw = newyaw;
dz = 1;
}
if(movetype == move_fly && du<4000){
newpitch = MaxAng*(asin(dp/du))/M_PIx2;
dz = .2;
}
if(movetype == move_roll && du<4000){
newpitch = MaxAng*(asin(dp/du))/M_PIx2;
dz = .3;
}
//while(newpitch<0)
// newpitch+=MaxAng;
if(pitch>MaxAng/2)
pitch -=MaxAng;
if(movetype == move_fly){
tmppitch = pitch - newpitch;
if(tmppitch<-6*Deg){
dpitch=6*Deg;
}
else if(tmppitch>6*Deg){
dpitch=-6*Deg;
}
else if(tmppitch<-3*Deg){
dpitch=3*Deg;
}
else if(tmppitch>3*Deg){
dpitch=-3*Deg;
}
else if(tmppitch<Deg){
dpitch=Deg;
}
else if(tmppitch>Deg){
dpitch=-Deg;
}
else{
dpitch = 0;
pitch = newpitch;
}
}
//sprintf(MyS,"%f %f %f %f %f %f %f",yaw/Deg,pitch/Deg,newyaw/Deg,newpitch/Deg,du,tmpyaw/Deg,tmppitch/Deg);
//Print(MyS);
if(Camera.next == Self){
Camera.iyaw = -tmpyaw;
Camera.ipitch = -tmppitch;
if(Camera.dpitch<0) Camera.dpitch = 0;
}
if(movetype == move_fly && du<2000 && MyShootTime < GameTime){
MyShootTime = .4+GameTime;
Tail->next = new entity_t("laser2.lwo",x,y,z,0,0,(dz*1000)+600,yaw,pitch,0);
//dz = .2;
if(!Tail->next) Print("WTF!?");
Tail->next->prev = Tail;
Tail = Tail->next;
Tail->lights(255,10,255,64,4);
Tail->setit(setmove,3);
Tail->thinktime = GameTime+3;
Tail->setsize(-5,-5,-5,5,5,5);
Tail->Owner = Self;
}
if(movetype == move_roll){
dpitch = 0;
dyaw /=2;
dz =150;
}
if(movetype == move_roll && du<4000 && MyShootTime < GameTime){
//dz = .3;
/*while(newyaw<0)
newyaw+=MaxAng;
while(newpitch<0)
newpitch+=MaxAng;
while(newyaw>=MaxAng)
newyaw-=MaxAng;
while(newpitch>=MaxAng)
newpitch-=MaxAng;*/
//sprintf(MyS,"%f %f %f",redx/dz,redz/dz,dz);
//Print(MyS);
float rdx = 2*redx/dz, rdz = 2*redz/dz;
Tail->next = new entity_t("laser1.lwo",x-rdx,y,z+rdz,0,0,500,newyaw,newpitch,0);
Tail->next->prev = Tail;
Tail = Tail->next;
if(!Tail) Print("WTF!?");
Tail->lights(255,255,10,64,4);
Tail->setit(setmove,3);
Tail->thinktime = GameTime+4;
Tail->setsize(-1,-1,-1,1,1,1);
Tail->Owner = Self;
Tail->next = new entity_t("laser1.lwo",x+rdx,y,z-rdz,0,0,500,newyaw,newpitch,0);
Tail->next->prev = Tail;
Tail = Tail->next;
if(!Tail) Print("WTF!?");
Tail->nolight = 1;
//Tail->lights(255,255,10,64,4);
Tail->setit(setmove,3);
Tail->thinktime = GameTime+4;
Tail->setsize(-1,-1,-1,1,1,1);
Tail->Owner = Self;
MyShootTime = 1+GameTime;
}
if(movetype == move_fly){
dz *=1000;
}
}
if (useinput){
/*ax = 0;
ay = 0;
az = 0;*/
//dx = 0;
if(movetype!= move_fly)
dy = 0;
apitch = 0;
aroll = 0;
ayaw = 0;
dpitch = 0;
droll = 0;
dyaw = 0;
dz = 0;//speed;
float speed;
if (keys[188])
dist-=128;
else if (keys[190])
dist+=128;
else if(keys[191]){
Camera.fov();
//sprintf(MyS,"%i",dist);
//Print(MyS);
}
if (keys[VK_SHIFT])
speed=128.f;
else if (keys[VK_CONTROL])
speed=16.f;
else if (keys['M'])
speed = 512.f;
else
speed=64.f;
//dz = 1024.f;
if (keys[VK_HOME]) dy+=speed;
else if (keys[VK_END]) dy-=speed;
if(keys['A']){
dz+=speed*8;
}
if(keys['Z']){
dz-=speed*8;
}
if(keys['X']){
dx-=speed;
}
if(keys['C']){
dx+=speed;
}
if (keys[VK_INSERT])
droll+=speed*8;
else if (keys[VK_DELETE])
droll-=speed*8;
if(keys['R']){
roll = 8192;
pitch = 0;
yaw = 0;
}
if(keys['T']){
roll = 0;
pitch = 8192;
yaw = 0;
}
if(keys['E']){
roll = 0;
pitch = 0;
yaw = 8192;
}
if(keys['F']){
roll = 0;
pitch = 8192;
yaw = 8192;
}
if(keys['W']){
roll = 0;
pitch = 4096;
yaw = 4096;
}
int tk=-120;
if(JoyActive){
tk = JoyRead(mainhwnd,joynum);
if(tk) JoyActive = 0;
int ugh;
ugh = JoyStats.dwYpos-JoyBias.Y;
dpitch-=((float)(ugh)/16.f);
//ugh = JoyStats.dwRpos-JoyBias.R;
//dyaw+=((float)(ugh)/16.f);
ugh = JoyStats.dwXpos-JoyBias.X;
dyaw+=((float)(ugh)/8.f);
ugh = JoyCaps.wZmax - JoyStats.dwZpos;//-JoyBias.Z;
dz+=((float)(ugh)/16.f);
if(JoyStats.dwButtons&1 && GameTime > MyShootTime){
MyShootTime = .1+GameTime;
/*entity_t *newe = Head;
while(newe->next){
newe=newe->next;
}*/
Tail->next = new entity_t("laser2.lwo",x,y,z,0,0,600+dz,yaw,pitch,0);
if(!Tail->next) Print("WTF!?");
Tail->next->prev = Tail;
Tail = Tail->next;
Tail->lights(255,10,255,64,4);
Tail->setit(setmove,3);
Tail->thinktime = GameTime+3;
Tail->setsize(-5,-5,-5,5,5,5);
Tail->Owner = Self;
}
if(JoyStats.dwButtons&2 && GameTime > MyShootTime){
Tail->next = new entity_t("laser1.lwo",x-2,y,z-2,0,0,500,yaw,pitch,0);
Tail->next->prev = Tail;
Tail = Tail->next;
if(!Tail) Print("WTF!?");
Tail->lights(255,255,10,64,4);
Tail->setit(setmove,3);
Tail->thinktime = GameTime+4;
Tail->setsize(-1,-1,-1,1,1,1);
Tail->Owner = Self;
Tail->next = new entity_t("laser1.lwo",x+2,y,z+2,0,0,500,yaw,pitch,0);
Tail->next->prev = Tail;
Tail = Tail->next;
if(!Tail) Print("WTF!?");
Tail->nolight = 1;
//Tail->lights(255,255,10,64,4);
Tail->setit(setmove,3);
Tail->thinktime = GameTime+4;
Tail->setsize(-1,-1,-1,1,1,1);
Tail->Owner = Self;
MyShootTime = 1+GameTime;
}
}
if (keys[VK_UP])
dpitch-=speed*8;
else if (keys[VK_DOWN])
dpitch+=speed*8;
if (keys[VK_LEFT]) {
//turn left
dyaw -= (speed*8);
}
else if (keys[VK_RIGHT]) {
//turn right
dyaw += (speed*8);
}
}
/*else {
sprintf(MyS,"(%1.1f %1.1f %1.1f)",// (%1.1f %1.1f %1.1f) (%1.1f %1.1f %1.1f) (%1.1f %1.1f %1.1f)",
dx,dy,dz);//,ax,ay,az,yaw,pitch,roll,dyaw,dpitch,droll);
Print(MyS);
}*/
if(movetype == 4 && dz >0){
az = -40;
}
if(movetype == 4 && dz <0){
az = 0;
dz = 0;
}
dx+=ax*dt;//Relative speeds
dy+=ay*dt;
dz+=az*dt;
ox = x;
oy = y;
oz = z;
if(movetype == move_roll){
//Print("roll");
dyaw +=ayaw*dt;
yaw += dyaw*dt;
dpitch +=apitch*dt;
roll += droll*dt;
while(roll < 0) roll +=MaxAng;
while(roll >= MaxAng) roll -=MaxAng;
c = Cos[(int)roll];
s = Sin[(int)roll];
pitch += (dpitch*c + dyaw*s)*dt;
yaw += (dyaw*c - dpitch*s)*dt;
while(yaw < 0) yaw +=MaxAng;
while(pitch < 0) pitch +=MaxAng;
while(yaw >= MaxAng) yaw -=MaxAng;
while(pitch >= MaxAng) pitch -=MaxAng;
while(roll < 0) roll +=MaxAng;
while(roll >= MaxAng) roll -=MaxAng;
float dxs=dx,dys=dy,dzs=dz;
dyr = dys;
c = Cos[(int)yaw];
s = Sin[(int)yaw];
dxr = dxs*c + dzs*s;
dzr = dzs*c - dxs*s;
dxs = dxr;
dzs = dzr;
x +=dxr*dt;
y +=dyr*dt;
z +=dzr*dt;
redx = dxr;
redy = dyr;
redz = dzr;
}
else if(movetype == move_fly){
//Print("fly");
float ndroll=0, ndpitch=0,ndyaw=0;
ndyaw = dyaw = dyaw + ayaw*dt;
//yaw += dyaw*dt;
ndpitch = dpitch = dpitch +apitch*dt;
ndroll = droll;
//roll += droll*dt;
if(roll < 0) roll +=MaxAng;
if(roll >= MaxAng) roll -=MaxAng;
c = Cos[(int)roll];
s = Sin[(int)roll];
ndpitch += (dpitch*c + dyaw*s);
ndyaw += (dyaw*c - dpitch*s);
yaw +=ndyaw*dt;
pitch +=ndpitch*dt;
//roll +=ndroll*dt;
while(yaw < 0) yaw +=MaxAng;
while(pitch < 0) pitch +=MaxAng;
while(yaw >= MaxAng) yaw -=MaxAng;
while(pitch >= MaxAng) pitch -=MaxAng;
while(roll < 0) roll +=MaxAng;
while(roll >= MaxAng) roll -=MaxAng;
float dxs=dx,dys=dy,dzs=dz;
//sprintf(MyS,"%f %f %f (%f %f)",dx,dy,dz,pitch,yaw);
c = Cos[(int)pitch];
s = Sin[(int)pitch];
dyr = dy*c - dz*s;
dzr = dz*c + dy*s;
dys = dyr;
dzs = dzr;
c = Cos[(int)yaw];
s = Sin[(int)yaw];
dxr = dxs*c + dzs*s;
dzr = dzs*c - dxs*s;
dxs = dxr;
dzs = dzr;
x +=dxr*dt;
y +=dyr*dt;
z +=dzr*dt;
redx = dxr;
redy = dyr;
redz = dzr;
}
else{
//Print("other");
yaw +=dyaw*dt;
pitch +=dpitch*dt;
roll +=droll*dt;
while(yaw < 0) yaw +=MaxAng;
while(pitch < 0) pitch +=MaxAng;
while(yaw >= MaxAng) yaw -=MaxAng;
while(pitch >= MaxAng) pitch -=MaxAng;
while(roll < 0) roll +=MaxAng;
while(roll >= MaxAng) roll -=MaxAng;
float dxs=dx,dys=dy,dzs=dz;
//sprintf(MyS,"%f %f %f (%f %f)",dx,dy,dz,pitch,yaw);
c = Cos[(int)pitch];
s = Sin[(int)pitch];
dyr = dy*c - dz*s;
dzr = dz*c + dy*s;
dys = dyr;
dzs = dzr;
c = Cos[(int)yaw];
s = Sin[(int)yaw];
dxr = dxs*c + dzs*s;
dzr = dzs*c - dxs*s;
dxs = dxr;
dzs = dzr;
x +=dxr*dt;
y +=dyr*dt;
z +=dzr*dt;
redx = dxr;
redy = dyr;
redz = dzr;
/*if(x>LevMax || x<0 || z>LevMax || z<0){
sprintf(MyS,"St: %f %f %f %f %f %f",s,c,dxs,dzs,yaw/Deg,pitch/Deg);
Print(MyS);
sprintf(MyS,"Md: %f %f %f",dx,dy,dz);
Print(MyS);
}*/
}
if(y>1024) y = 1024;
if(y<-256) y = -256;
if(flag==1){
MatMakeIdent(rotc);
MatMakeYRot(roty, yaw);
MatMakeXRot(rotx, pitch);
MatMakeZRot(rotz, roll);
MatMultMat(rotx,rote,rotc);
MatMultMat(roty,rote,rotc);
MatMultMat(rotz,rote,rotc);
Camx = x;
Camy = y;
Camz = z;
}
if(flag==2){
float rdx,rdy,rdz;
dz = -192;
dx = 0;
dy = 0;
GDx=0;
GDy=0;
//GDs=0;
//if(mouseon)
MouseRead(mainhwnd);
dyaw+=GDx*10;
dpitch+=GDy;
if(next->die)
next=prev;
if(movetype != 4){
if(dpitch>MaxAng/2)
dpitch -=MaxAng;
int tmppitch = dpitch - ipitch;
if(tmppitch<-2*Deg){
dpitch+=Deg;
}
else if(tmppitch>2*Deg){
dpitch-=Deg;
}
if(dyaw>MaxAng/2)
dyaw -=MaxAng;
int tmpyaw = dyaw - iyaw;
if(tmpyaw<-2*Deg){
dyaw+=Deg;
}
else if(tmpyaw>2*Deg){
dyaw-=Deg;
}
}
yaw = next->yaw+dyaw;
pitch = next->pitch+dpitch+3*Deg;
//roll = next->roll;
while(yaw>=MaxAng)
yaw -=MaxAng;
while(yaw<0)
yaw +=MaxAng;
while(pitch>=MaxAng)
pitch -=MaxAng;
while(pitch<0)
pitch +=MaxAng;
c = Cos[(int)pitch];
s = Sin[(int)pitch];
rdy = dy*c - dz*s;
rdz = dz*c + dy*s;
dy = rdy;
dz = rdz;
c = Cos[(int)yaw];
s = Sin[(int)yaw];
rdx = dx*c + dz*s;
rdz = dz*c - dx*s;
dx = rdx;
dz = rdz;
Camx = x = next->x + dx;
Camy = y = next->y + dy;
Camz = z = next->z + dz;
}
if(flag==3){
if(next->die)
next=prev;
x=next->x;
y=next->y;
z=next->z;
yaw = next->yaw;
pitch = next->pitch;
roll = next->roll;
MatMakeIdent(rotc);
MatMakeYRot(roty, yaw);
MatMakeXRot(rotx, pitch);
MatMakeZRot(rotz, roll);
MatMultMat(rotz,rote,rotc);
MatMultMat(rotx,rote,rotc);
MatMultMat(roty,rote,rotc);
Camx = x;
Camy = y;
Camz = z;
}
collide();
return 1;
}
void entity_t::setit(int modify, float value){
switch(modify){
case setflag:
flag = value;
break;
case setuseinput:
useinput = value;
break;
case setyaw:
yaw=value;
break;
case setpitch:
pitch=value;
break;
case setroll:
roll=value;
break;
case setx:
x=value;
break;
case sety:
y=value;
break;
case setz:
z=value;
break;
case setlight:
light=value;
break;
case setrad:
rad=value;
break;
case setdyaw:
dyaw=value;
break;
case setdpitch:
dpitch=value;
break;
case setdroll:
droll=value;
break;
case setmove:
movetype=value;
break;
default:
break;
}//Switch
}
void entity_t::lights(float Red, float Green, float Blue, float Alpha,float hard){
lightr = Red;
lightg = Green;
lightb = Blue;
lighta = Alpha;
lighth = hard;
light = 1;
}
void entity_t::PrintStats(){
sprintf(MyS,"Camera X: %f,Y: %f,Z: %f,",x,y,z);
Print(MyS);
sprintf(MyS,"Camera Yaw: %f,Pitch: %f,Roll: %f",yaw,pitch,roll);
Print(MyS);
}
void entity_t::castlight(entity_t *Other){
int tmp,rgb;
float dist,dist2,rdx,rdy,rdz,inten,al2=Other->lighta*Other->lighth;
al2*=al2;
if(Other->light == 0) return;
for(tmp=0;tmp<NumVerts;tmp++){
rdx = Other->x-rVerts[tmp].x;
rdy = Other->y-rVerts[tmp].y;
rdz = Other->z-rVerts[tmp].z;
dist2 = rdx*rdx+rdy*rdy+rdz*rdz;
if(dist2>al2) continue;
dist= sqrt(dist2);
inten = Other->lighth-dist/Other->lighta;//(dist2/382.5-5*dist/3+255)/255;//((dist2/255-dist+255)/255);
lit[tmp].r+=(Other->lightr*inten)/255;
lit[tmp].g+=(Other->lightg*inten)/255;
lit[tmp].b+=(Other->lightb*inten)/255;
if(lit[tmp].r>2) lit[tmp].r = 2;
if(lit[tmp].g>2) lit[tmp].g = 2;
if(lit[tmp].b>2) lit[tmp].b = 2;
if(lit[tmp].r<0) lit[tmp].r = 0;
if(lit[tmp].g<0) lit[tmp].g = 0;
if(lit[tmp].b<0) lit[tmp].b = 0;
}
}
entity_t::CameraRender(){
float yaw2,pitch2,roll2;
yaw2 = MaxAng - yaw;
pitch2 = MaxAng - pitch;
roll2 = MaxAng - roll;
if(yaw2 < 0) yaw2 +=MaxAng;
if(pitch2 < 0) pitch2 +=MaxAng;
if(roll2 < 0) roll2 +=MaxAng;
if(yaw2 >= MaxAng) yaw2 -=MaxAng;
if(pitch2 >= MaxAng) pitch2 -=MaxAng;
if(roll2 >= MaxAng) roll2 -=MaxAng;
MatMakeIdent(rotc);
MatMakeYRot(roty, yaw2);
MatMakeXRot(rotx, pitch2);
MatMakeZRot(rotz, roll2);
MatMultMat(rotz,rotc,rotc);
MatMultMat(rotx,rotc,rotc);
MatMultMat(roty,rotc,rotc);
MatMakeIdent(rote);
MatMakeYRot(roty, yaw);
MatMakeXRot(rotx, pitch);
MatMakeZRot(rotz, roll);
//MatMultMat(rotx,rote,rote);
MatMultMat(roty,rote,rote);
//MatMultMat(rotz,rote,rote);
int tmp,tmp2;
for(tmp = 0;tmp<3;tmp++){
FoVTriT[tmp].x = FoVTri[tmp].x;//+gridsep*GridNum/4;
FoVTriT[tmp].y = FoVTri[tmp].y;
FoVTriT[tmp].z = FoVTri[tmp].z;//+gridsep*GridNum/4;
PointMatMult(&FoVTriT[tmp],&FoVTriT[tmp],rote);
FoVTriT[tmp].x += Camx;
FoVTriT[tmp].y += Camy;
FoVTriT[tmp].z += Camz;
}
//sprintf(MyS,"%f %f %f",FoVTriT[0].x,FoVTriT[0].y,FoVTriT[0].z);
//Print(MyS);
for(tmp = 0;tmp<3;tmp++){
tmp2 = tmp+1;
if(tmp2 >2) tmp2 = 0;
Tridx[tmp] = -(FoVTriT[tmp].x - FoVTriT[tmp2].x);
Tridz[tmp] = FoVTriT[tmp].z - FoVTriT[tmp2].z;
//Trim[tmp] = -Tridz[tmp]/Tridx[tmp];
Trib[tmp] = Tridx[tmp]*FoVTriT[tmp].z + Tridz[tmp]*FoVTriT[tmp].x;
}
/* for(tmp = 0;tmp<3;tmp++){
FoVTriT[tmp].ooz =
FoVTriT[tmp].oow = 1/(FoVTri[tmp].z+1);
FoVTriT[tmp].x = Camzoomx*FoVTri[tmp].x*FoVTriT[tmp].ooz+wHWidth+vertex_snapper;
FoVTriT[tmp].y = Camzoomy*(FoVTri[tmp].y+.1)*FoVTriT[tmp].ooz+wHHeight+vertex_snapper;
FoVTriT[tmp].x -=vertex_snapper;
FoVTriT[tmp].y -=vertex_snapper;
}
FoVTriT[0].a = 255;
FoVTriT[1].a = 255;
FoVTriT[2].a = 255;
guDrawTriangleWithClip(&FoVTriT[0],&FoVTriT[1],&FoVTriT[2]);*/
for(tmp = 0;tmp<NumLand;tmp++){
//sprintf(MyS,"%i",tmp);
//Print(MyS);
land[tmp].render(rotc,x,y,z);
}
return 1;
}
//lwo stuff
short BigShort (short l)
{
byte b1,b2;
b1 = l&255;
b2 = (l>>8)&255;
return (b1<<8) + b2;
}
short LittleShort (short l)
{
return l;
}
int BigLong (int l)
{
byte b1,b2,b3,b4;
b1 = l&255;
b2 = (l>>8)&255;
b3 = (l>>16)&255;
b4 = (l>>24)&255;
return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
}
int LittleLong (int l)
{
return l;
}
float BigFloat (float l)
{
union {byte b[4]; float f;} in, out;
in.f = l;
out.b[0] = in.b[3];
out.b[1] = in.b[2];
out.b[2] = in.b[1];
out.b[3] = in.b[0];
return out.f;
}
float LittleFloat (float l)
{
return l;
}